import { createRouter, createWebHistory } from 'vue-router'
// pinia
import { useNavigationStore } from '@/store/index'
// 進度條
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({
    easing: 'ease', // 动画方式
    speed: 500, // 递增进度条的速度
    showSpinner: false, // 是否显示加载ico
    trickleSpeed: 200, // 自动递增间隔
    minimum: 0.3,// 初始化时的最小百分比,
})

// 引入路由
import routerConfig from "./config"
const routes = routerConfig

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

// 路由守衛
router.beforeEach((to, from, next) => {
    const navigationStore = useNavigationStore()
    NProgress.start()
    // 根據路由meta信息設置頂部導航
    if (to.meta.topNav) {
        navigationStore.setActiveTopNav(to.meta.topNav)
    }

    next()
})

router.afterEach(() => {
    NProgress.done()
})

export default router